﻿using System;
using System.Collections.Generic;
using System.Text;
using HAVNet.Core.String;


namespace HAVNet.Intros.AST
{
    public class ASTTypeDeclStruct : ASTNamespaceTypeDecl
    {
        public bool isPartial { get; set; }
        public readonly ASTTypeParamList        typeParamList   = new ASTTypeParamList      ();
        public readonly ASTTypeNames            baseTypeNames   = new ASTTypeNames          ();
        public readonly ASTTypeConstraintList   constraints     = new ASTTypeConstraintList ();
        public readonly ASTMemberDecls          members         = new ASTMemberDecls        ();

        public override string ToString ()
        {
            depth++;

            string mods = "";

            if (Mods.has(modifiers, Mods.unsafeMod)) mods += "unsafe ";
            if (Mods.has(modifiers, Mods.publicMod)) mods += "public ";
            if (Mods.has(modifiers, Mods.privateMod)) mods += "private ";
            if (Mods.has(modifiers, Mods.internalMod)) mods += "internal ";
            if (Mods.has(modifiers, Mods.protectedMod)) mods += "protected ";

            if (isPartial) mods += "partial ";

            string ret = (baseTypeNames.Count > 0) ?
                Strings.tab(depth) + mods + string.Format("struct {0}{1}: {2} {3}", name, typeParamList, baseTypeNames, constraints)
                :
                Strings.tab(depth) + mods + string.Format("struct {0}{1} {2}", name, typeParamList, constraints);

            ret += Environment.NewLine + Strings.tab(depth) + "{";
            ret += Environment.NewLine + members.ToString();
            ret += Environment.NewLine + Strings.tab(depth) + "}";
            if (hasFinalComma) ret += ";";

            depth--;
            return ret;
        }
    }
}
